<?php 
/**
* @author sfhq1610 wangzai
*  @abstract  can quick creat warehouse!
*/
?>
<fieldset class="a-right">
        <?php echo $this->getChildHtml('create_address') ?>
</fieldset>
<?php echo $this->getChildHtml('details'); ?>
<?php echo $this->getChildHtml('grid') ?>

<script type="text/javascript">
		var warehouse = {};
		warehouse.address =Class.create();
		warehouse.address.prototype = {
		initialize : function(grid,containerId) {
			        this.containerId = containerId;
			        this.grid = grid;
			    },
			  updateAddress : function() {
			        this.grid.reload(null);
			    },

		    createPopup:function(url){
		    	  if (this.win && !this.win.closed) {
		              this.win.close();
		          }

		          this.win = window.open(url, '',
		                  'width=1000,height=700,resizable=1,scrollbars=1');
		          this.win.focus();
			    },	
			   createAddress:function(createurl){
				 this.createPopup(createurl)
						},
			    editAddress:function(){
			    	 this.createPopup(this.editAddressUrl)
				}	
		}
	var warehouse = new  	warehouse.address(<?php echo $this->getGridJsObject() ?>);
		function createWarehouseAddress(idPrefix, generateUrl) {
			var grid = <?php echo $this->getGridJsObject() ?>;
		    $(idPrefix + 'quickcreate_form').removeClassName('ignore-validate');
		    var validationResult = $(idPrefix + 'quickcreate_form').select('input',
		            'select', 'textarea').collect( function(elm) {
		        return Validation.validate(elm, {
		            useTitle :false,
		            onElementValidate : function() {
		            }
		        });
		    }).all();
		    $(idPrefix + 'quickcreate_form').addClassName('ignore-validate');

		    if (!validationResult) {
		        return;
		    }
		    var elements = $(idPrefix + 'quickcreate_form').select('input', 'select', 'textarea');

		    var params = Form.serializeElements(elements, true);
		    params.form_key = FORM_KEY;
		    $('messages').update();
		    var couponCodesGrid = eval(grid);
		    new Ajax.Request(generateUrl, {
		        parameters :params,
		        method :'post',
		        onComplete : function (transport, param){
		            var response = false;
		            if (transport && transport.responseText) {
		                response = eval('(' + transport.responseText + ')');
		            }
		            if (couponCodesGrid) {
		                couponCodesGrid.reload();
		            }
		            if (response && response.messages) {
		                $('messages').update(response.messages);
		            }
		            if (response && response.error) {
		                alert(response.error);
		            }
		        }
		    });
		} 
</script>